package cn.iocoder.yudao.module.crossborder.logistics.api;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crossborder.logistics.api.dto.LogisticsDTO;
import cn.iocoder.yudao.module.crossborder.logistics.api.dto.TrackingDTO;
import cn.iocoder.yudao.module.crossborder.logistics.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * 物流管理 API 接口
 *
 * @author LHL
 */
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
@Tag(name = "RPC 服务 - 物流管理")
public interface LogisticsApi {

    String PREFIX = ApiConstants.PREFIX + "/logistics";

    @GetMapping(PREFIX + "/get")
    @Operation(summary = "获得物流记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    CommonResult<LogisticsDTO> getLogistics(@RequestParam("id") @NotNull Long id);

    @GetMapping(PREFIX + "/list")
    @Operation(summary = "获得物流记录列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    CommonResult<List<LogisticsDTO>> getLogisticsList(@RequestParam("ids") @NotNull List<Long> ids);

    @PostMapping(PREFIX + "/create")
    @Operation(summary = "创建物流记录")
    CommonResult<Long> createLogistics(@RequestBody @Valid LogisticsDTO logistics);

    @GetMapping(PREFIX + "/tracking/get")
    @Operation(summary = "获取物流跟踪信息")
    @Parameter(name = "trackingNumber", description = "跟踪号", required = true, example = "SF1234567890")
    CommonResult<TrackingDTO> getTracking(@RequestParam("trackingNumber") @NotNull String trackingNumber);

    @PostMapping(PREFIX + "/freight/calculate")
    @Operation(summary = "计算运费")
    @Parameter(name = "orderId", description = "订单编号", required = true, example = "1024")
    @Parameter(name = "weight", description = "重量(kg)", required = true, example = "1.5")
    @Parameter(name = "destination", description = "目的地", required = true, example = "上海")
    CommonResult<BigDecimal> calculateFreight(@RequestParam("orderId") @NotNull Long orderId,
                                             @RequestParam("weight") @NotNull BigDecimal weight,
                                             @RequestParam("destination") @NotNull String destination);

    @PostMapping(PREFIX + "/ship")
    @Operation(summary = "发货")
    @Parameter(name = "orderId", description = "订单编号", required = true, example = "1024")
    @Parameter(name = "providerId", description = "物流服务商编号", required = true, example = "2048")
    CommonResult<Boolean> ship(@RequestParam("orderId") @NotNull Long orderId,
                              @RequestParam("providerId") @NotNull Long providerId);

    @PostMapping(PREFIX + "/update-status")
    @Operation(summary = "更新物流状态")
    @Parameter(name = "logisticsId", description = "物流编号", required = true, example = "1024")
    @Parameter(name = "status", description = "状态", required = true, example = "2")
    CommonResult<Boolean> updateStatus(@RequestParam("logisticsId") @NotNull Long logisticsId,
                                      @RequestParam("status") @NotNull Integer status);

}
